<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends MY_Controller {
// Some code happens here
    public function __construct()
    {
        parent:: __construct();
        $this->loadTemplate();
        $this->load->helper("url");
	    $this->load->model('sanpham');
        $this->load->library('url'); 
        $this->load->library('utils');   
        $this->load->helper('html');
		$this->load->helper('text');
	    $this->load->library('parser');
        $this->load->library('pagination');
        $this->load->library('currency');
    }
      public function loadTemplate()
      {
          $this->template->write_view('header','main/header');
          //$this->template->write_view('menu','main/menu');
        //  $this->template->write_view('slide','main/slide');
        //  $this->template->write_view('news','main/new');
          $this->template->write_view('footer','main/footer');
      }
	
    public function catalogs($name,$offset = 0,$perpage = 7)
    {
        
        $content['html'] = '';
        switch($name)
        {
            case "gioithieu":
                $this->template->write_view('content','home/gioithieu');
                $menu['active5'] = "active";
                
                break;
            case "lienhe":
                $this->template->write_view('content','home/lienhe');
                $menu['active6'] = "active";
                break;
            case "laptop":
                 $content['html'] = $this->construct_laptop($offset,$perpage);
                  $this->template->write_view('slide','main/slide');
                  $this->template->write_view('news','main/new');
                 $this->template->write_view('searchzone','main/searchzone');
                $menu['active2'] = "active";
                break;
            case "tablet":
                 $content['html'] =$this->construct_tablet($offset,$perpage);
                 $this->template->write_view('slide','main/slide');
                  $this->template->write_view('news','main/new'); 
                 $this->template->write_view('searchzone','main/searchzone');
                 $menu['active3'] = "active";
                break;
                
            case "phone":
                $content['html']= $this->construct_phone($offset,$perpage);
                $this->template->write_view('slide','main/slide');
                $this->template->write_view('news','main/new');
                $this->template->write_view('searchzone','main/searchzone');            
                $menu['active4'] = "active";
                break;   
            default:
                $this->template->write_view('slide','main/slide');
                $this->template->write_view('news','main/new');
                $this->template->write_view('searchzone','main/searchzone');
                $menu['active1'] = "active";
       
        }
        $this->template->parse_view('content','home/content',$content,true);
        $this->template->parse_view('menu','main/menu',$menu,true);
        $this->template->render();
       
    }
    public function catalogs_ajax($name,$offset = 0,$perpage = 7)
    {
        switch($name)
        {
            case "laptop":
                 echo $this->construct_laptop($offset,$perpage);
                break;
            case "tablet":
                 echo $this->construct_tablet($offset,$perpage);
                break;
            case "phone":
                echo $this->construct_phone($offset,$perpage);
                break;   
        }

    }
    
    
    public function construct_laptop($offset = 0,$perpage = 7)
    {
        $config['base_url'] = site_url('category/catalogs_ajax/laptop');
		$config['total_rows'] = $this->sanpham->get_num_product_with_category('laptop_product');
	    $config['per_page'] = $perpage;
        $config['cur_page'] = $offset/7;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';
	    $this->pagination->initialize($config);
        //Du lieu rent paging
        $pdata['html'] = $this->pagination->create_links();
        $data['paging'] = $this->parser->parse('home/listproduct_paging',$pdata,true);
        
        /* phan thong tin */
        $item = "";
        $products = $this->sanpham->get_product_with_category('laptop_product',$perpage,$offset);
        foreach($products as $product)
        {
          $ts = array();
          foreach($this->sanpham->get_str_thongso($product['ID']) as $thongso => $value)
          {
            array_push($ts,$value['TS']);
          }
            $product['str_thongso'] =implode(", ",$ts);
            $product['gia'] = $this->currency->convert_to_vnd($this->sanpham->get_product_prices($product['ID']));
            $product['image'] = $this->utils->get_url_img($this->sanpham->get_images($product['ID'],true));
            $product['link']= 'san-pham/p'.$this->url->get_friendly_url($product['ID'],$product['TenSP']); 
            $item .= $this->parser->parse('home/simpl_product',$product,true);
        }
         $data['lstProduct'] = $item;
         
         //Hot Product
          $data['hot_product'] =""; 
          $item = "";
          $products = $this->sanpham->get_hot_product(10);
            foreach($products as $product)
            {
                $product['gia'] = $this->currency->convert_to_vnd($this->sanpham->get_product_prices($product['ID']));
                $product['image'] = $this->utils->get_url_img($this->sanpham->get_images($product['ID'],true));
                $product['link']= 'san-pham/p'.$this->url->get_friendly_url($product['ID'],$product['TenSP']); 
                $item .= $this->parser->parse('home/very_simpl_product',$product,true);
            }
           $data['hot_product'] = $item; 
         //End - hot Product
         // End Siminar Product
         /* phan thong tin */
         
         
         
         return $this->parser->parse('home/listproduct',$data,true);
 
    }
      public function construct_tablet($offset = 0,$perpage = 7)
    {
        $config['total_rows'] = $this->sanpham->get_num_product_with_category('tablet_product');

        $config['base_url'] = site_url('category/catalogs_ajax/tablet');
        $config['per_page'] = $perpage;
        $config['cur_page'] = $offset/7;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';
	    $this->pagination->initialize($config);
        //Du lieu rent paging
        $pdata['html'] = $this->pagination->create_links();
        $data['paging'] = $this->parser->parse('home/listproduct_paging',$pdata,true);
        if($config['total_rows'] <=0)
        {
        /* phan thong tin */
           $item = "Sản Phẩm Đang Cập Nhật";
        }
        else
        {
            $products = $this->sanpham->get_product_with_category('tablet_product',$perpage,$offset);
            foreach($products as $product)
            {
              $ts = array();
              foreach($this->sanpham->get_str_thongso($product['ID']) as $thongso => $value)
              {
                array_push($ts,$value['TS']);
              }
                $product['str_thongso'] =implode(", ",$ts);
                $product['gia'] = $this->currency->convert_to_vnd($this->sanpham->get_product_prices($product['ID']));
                $product['image'] = $this->utils->get_url_img($this->sanpham->get_images($product['ID'],true));
                $item .= $this->parser->parse('home/simpl_product',$product,true);
            }

        }
        $data['lstProduct'] = $item;
             /* phan thong tin */
                      //Hot Product
              $data['hot_product'] =""; 
              $item = "";
              $products = $this->sanpham->get_hot_product(10);
                foreach($products as $product)
                {
                    $product['gia'] = $this->currency->convert_to_vnd($this->sanpham->get_product_prices($product['ID']));
                    $product['image'] = $this->utils->get_url_img($this->sanpham->get_images($product['ID'],true));
                    $product['link']= 'san-pham/p'.$this->url->get_friendly_url($product['ID'],$product['TenSP']); 
                    $item .= $this->parser->parse('home/very_simpl_product',$product,true);
                }
               $data['hot_product'] = $item; 
             //End - hot Product
         return $this->parser->parse('home/listproduct',$data,true);
    }
      public function construct_phone($offset = 0,$perpage = 7)
    {
   		$config['total_rows'] = $this->sanpham->get_num_product_with_category('iphone_product');
        $config['base_url'] = site_url('category/catalogs_ajax/phone');
	    $config['per_page'] = $perpage;
        $config['cur_page'] = $offset/7;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';
	    $this->pagination->initialize($config);
        //Du lieu rent paging
        $pdata['html'] = $this->pagination->create_links();
        $data['paging'] = $this->parser->parse('home/listproduct_paging',$pdata,true);
         if($config['total_rows'] <=0)
        {
        /* phan thong tin */
           $item = "Sản Phẩm Đang Cập Nhật";
        }
        else
        {
        /* phan thong tin */
            $item = "";
            $products = $this->sanpham->get_product_with_category('iphone_product',$perpage,$offset);
            foreach($products as $product)
            {
              $ts = array();
              foreach($this->sanpham->get_str_thongso($product['ID']) as $thongso => $value)
              {
                array_push($ts,$value['TS']);
              }
                $product['str_thongso'] =implode(", ",$ts);
                $product['gia'] = $this->currency->convert_to_vnd($this->sanpham->get_product_prices($product['ID']));
                $product['image'] = $this->utils->get_url_img($this->sanpham->get_images($product['ID'],true));
                $item .= $this->parser->parse('home/simpl_product',$product,true);
            }
        }
         $data['lstProduct'] = $item;
                  //Hot Product
          $data['hot_product'] =""; 
          $item = "";
          $products = $this->sanpham->get_hot_product(10);
            foreach($products as $product)
            {
                $product['gia'] = $this->currency->convert_to_vnd($this->sanpham->get_product_prices($product['ID']));
                $product['image'] = $this->utils->get_url_img($this->sanpham->get_images($product['ID'],true));
                $product['link']= 'san-pham/p'.$this->url->get_friendly_url($product['ID'],$product['TenSP']); 
                $item .= $this->parser->parse('home/very_simpl_product',$product,true);
            }
           $data['hot_product'] = $item; 
         //End - hot Product
         /* phan thong tin */
         return $this->parser->parse('home/listproduct',$data,true);
    }
  
  
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */